import React from 'react'
import './css/task.less';
// import EquipmentTest  from './coretask/EquipmentTest';
import Experience  from './coretask/Experience';
import BuyRegularclass  from './coretask/BuyRegularclass';
import Preview  from './coretask/Preview';
import InClass  from './coretask/InClass';
import EndNormal  from './coretask/EndNormal';
import EndAbnormal  from './coretask/EndAbnormal';
import NotAtThe  from './coretask/NotAtThe';
import Absent  from './coretask/Absent';
import CourseSection  from './coretask/CourseSection';
import http from '../../utils/http';
import IsArranging  from './coretask/IsArranging';

class Task extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
       card: '',
       status18:"A1",
       classpush:[],
       test:"",
       isArranging:false,
       RegularclassId:"", //常规课课程id
       experienceClassVo:{},  //体验课信息，课节数和价格
       isBuyExperienceClass:false,
       haizi:""
    };
   
  }

test=()=>{
  this.setState({haizi:"fff"})
 
}

iscountdown=(courseTabVo)=>{
  
  if(Number(courseTabVo.status)===1){ 
    var a=new Date();
    let nowTime=a.getTime();
    let yesNo=Number(courseTabVo.beginTime)-Number(nowTime);
    
    if(yesNo>24*60*60*1000){
      
      return 1
    }else{
       
      return 2
    }
    
  }else{
    
    return false
    
  }
}

// 选择课程状态
chooseClassState=()=>{
    http
        .get('tab/findTab')
        .then(data => {
          this.setState({
            card:data,
            isArranging:data.inClassVo.isInclass,
            RegularclassId:data.productId,
            experienceClassVo:data.experienceClassVo || {}
          })
          const classpush = []
          
          data.courseTabVosList && data.courseTabVosList.map((item,index)=>{
            if(item.type===2){
              if(item.courseTabVo.type===1&&this.iscountdown(item.courseTabVo)===1){
                classpush.push({classinfo:item,status18:"T1",itemindex:index})
              }else if(item.courseTabVo.type===1&&this.iscountdown(item.courseTabVo)===2){
                classpush.push({classinfo:item,status18:"T2",itemindex:index})
                // this.setState({status18:"T2",itemindex:index})
              }else if(item.courseTabVo.type===1&&item.courseTabVo.status===3){
                classpush.push({classinfo:item,status18:"T3",itemindex:index})
                // this.setState({status18:"T3",itemindex:index})
              }else if(item.courseTabVo.type===1&&item.courseTabVo.status===4){
                classpush.push({classinfo:item,status18:"T4",itemindex:index})
                // this.setState({status18:"T4",itemindex:index})
              }else if(item.courseTabVo.type===1&&item.courseTabVo.status===5){
                classpush.push({classinfo:item,status18:"T5",itemindex:index})
                // this.setState({status18:"T5",itemindex:index})
              }else if(item.courseTabVo.type===1&&item.courseTabVo.status===6){
                classpush.push({classinfo:item,status18:"T6",itemindex:index})
                // this.setState({status18:"T6",itemindex:index})
              }else if(item.courseTabVo.type===2&&this.iscountdown(item.courseTabVo)===1){
                classpush.push({classinfo:item,status18:"N1",itemindex:index})
                // this.setState({status18:"N1",itemindex:index})
              }else if(item.courseTabVo.type===2&&this.iscountdown(item.courseTabVo)===2){
                classpush.push({classinfo:item,status18:"N2",itemindex:index})
                // this.setState({status18:"N2",itemindex:index})
              }else if(item.courseTabVo.type===2&&item.courseTabVo.status===3){
                classpush.push({classinfo:item,status18:"N3",itemindex:index})
                // this.setState({status18:"N3",itemindex:index})
              }else if(item.courseTabVo.type===2&&item.courseTabVo.status===4){
                classpush.push({classinfo:item,status18:"N4",itemindex:index})
                // this.setState({status18:"N4",itemindex:index})
              }else if(item.courseTabVo.type===2&&item.courseTabVo.status===5){
                classpush.push({classinfo:item,status18:"N5",itemindex:index})
                // this.setState({status18:"N5",itemindex:index})
              }else if(item.courseTabVo.type===2&&item.courseTabVo.status===6){
                classpush.push({classinfo:item,status18:"N6",itemindex:index})
                // this.setState({status18:"N6",itemindex:index})
              }else if(item.courseTabVo.type===3&&this.iscountdown(item.courseTabVo)===1){
                classpush.push({classinfo:item,status18:"R1",itemindex:index})
                // this.setState({status18:"R1",itemindex:index})
              }else if(item.courseTabVo.type===3&&this.iscountdown(item.courseTabVo)===2){
                classpush.push({classinfo:item,status18:"R2",itemindex:index})
                // this.setState({status18:"R2",itemindex:index})
              }else if(item.courseTabVo.type===3&&item.courseTabVo.status===3){
                classpush.push({classinfo:item,status18:"R3",itemindex:index})
                // this.setState({status18:"R3",itemindex:index})
              }else if(item.courseTabVo.type===3&&item.courseTabVo.status===4){
                classpush.push({classinfo:item,status18:"R4",itemindex:index})
                // this.setState({status18:"R4",itemindex:index})
              }else if(item.courseTabVo.type===3&&item.courseTabVo.status===5){
                classpush.push({classinfo:item,status18:"R5",itemindex:index})
                // this.setState({status18:"R5",itemindex:index})
              }else if(item.courseTabVo.type===3&&item.courseTabVo.status===6){
                classpush.push({classinfo:item,status18:"R6",itemindex:index})
                // this.setState({status18:"R6",itemindex:index})
              }
            }else{
              classpush.push({classinfo:item,status18:"A6",itemindex:index})
                // this.setState({status18:"A6"})
            }
            return ""
          })
          this.setState({
            classpush
          })
        }, err => {
        })
  }      
// 加载任务卡
loadercard=(status)=>{
    switch(status.status18){
    case "T1": return   <NotAtThe className="Preview" status={status} status18="T" index={status.itemindex} key={status.classinfo.courseTabVo
.currentClassId}></NotAtThe> 
    case "T2": return   <Preview className="Preview" status={status} status18="T" index={status.itemindex} countdown={this.chooseClassState} key={status.classinfo.courseTabVo
      .currentClassId   }></Preview>
    case "T3": return   <InClass className="inClass"status={status}  status18="T" index={status.itemindex} countdown={this.chooseClassState} key={status.classinfo.courseTabVo
      .currentClassId}></InClass> 
    case "T4": return   <EndNormal className="endNormal" status={status} status18="T" index={status.itemindex}key={status.classinfo.courseTabVo
      .currentClassId}></EndNormal>
    case "T5": return  <EndAbnormal className="endAbnormal" status={status} status18="T" index={status.itemindex} key={status.classinfo.courseTabVo
      .currentClassId}></EndAbnormal>
    case "T6": return    <Absent className="absencct" status={status} status18="N" index={status.itemindex} key={status.classinfo.courseTabVo
      .currentClassId}></Absent>
    case "N1": return   <NotAtThe className="Preview" status={status} status18="N" index={status.itemindex} key={status.classinfo.courseTabVo
      .currentClassId}></NotAtThe> 
    case "N2": return   <Preview className="Preview" status={status} status18="N" index={status.itemindex} countdown={this.chooseClassState} key={status.classinfo.courseTabVo
      .currentClassId}></Preview>
    case "N3": return   <InClass className="inClass" status={status} status18="N" index={status.itemindex} countdown={this.chooseClassState} key={status.classinfo.courseTabVo
      .currentClassId}></InClass> 
    case "N4": return   <EndNormal className="endNormal" status={status} status18="N" index={status.itemindex} key={status.classinfo.courseTabVo
      .currentClassId}></EndNormal>
    case "N5": return    <EndAbnormal className="endAbnormal" status={status} index={status.itemindex} key={status.classinfo.courseTabVo
      .currentClassId}></EndAbnormal>
    case "N6": return    <Absent className="absencct" status={status} status18="N" index={status.itemindex} key={status.classinfo.courseTabVo
      .currentClassId}></Absent>
    case "R1": return   <NotAtThe className="Preview" status={status} status18="R" index={status.itemindex} key={status.classinfo.courseTabVo
      .currentClassId}></NotAtThe> 
    case "R2": return   <Preview className="Preview" status={status} status18="R" index={status.itemindex} countdown={this.chooseClassState} key={status.classinfo.courseTabVo
      .currentClassId}></Preview>
    case "R3": return   <InClass className="inClass" status={status} status18="R" index={status.itemindex} countdown={this.chooseClassState} key={status.classinfo.courseTabVo
      .currentClassId}></InClass> 
    case "R4": return   <EndNormal className="endNormal" status={status} status18="R" index={status.itemindex} key={status.classinfo.courseTabVo
      .currentClassId}></EndNormal>
    case "R5": return    <EndAbnormal className="endAbnormal" status={status} status18="R" index={status.itemindex} key={status.classinfo.courseTabVo
      .currentClassId}></EndAbnormal>
    case "R6": return    <Absent className="absencct" status={status} status18="R" index={status.itemindex} key={status.classinfo.courseTabVo
      .currentClassId}></Absent>
    case "A6": return    <CourseSection className="courseSection" status={status} status18="T" index={status.itemindex} key={status.classinfo.courseTabVo
      .currentClassId}></CourseSection>
    default : return ""
    }
 
}


 //设备检测，体验课推荐，以及常规课推荐模块判断。
 solveCardInformation=(data) => {
    if(!data){
      return　(<div></div>)
    }else{
  //  是否进行设备检测
    if(!data.isDeviceProbing){
          // 是否购买体验课
      if(!data.isBuyExperienceClass){
        return (<div>
                  {/* 引入设备检测模块  */}
                  {/* <EquipmentTest className="equipment"  ></EquipmentTest> */}
                  {/* 引入体验课推荐模块 */}
                  <Experience className="experience" test={this.props.main}  experienceClassVo={this.state.experienceClassVo} isBuyExperienceClass={this.state.isBuyExperienceClass}></Experience>
                </div>)
      }
      else{
        if(data.isRegularClass){
          return (<div>
                    {/* 引入设备检测模块  */}
                    {/* <EquipmentTest className="equipment" test={this.buyCourse} ></EquipmentTest> */}
                    {/*引入常规课购买模块 */}
                    {/* <BuyRegularclass className="buyclass"  test={this.props.main} level={this.state.card.level}></BuyRegularclass> */}
                  </div>)
        }else{
          return (<div>
                    {/* 引入设备检测模块  */}
                    <BuyRegularclass className="buyclass"  test={this.props.main} level={this.state.card.level}></BuyRegularclass>
                  </div>)
        }
      }
    }else{
         // 是否购买体验课
      if(!data.isBuyExperienceClass){
        return (<div>
                {/* 引入体验可推荐模块 */}
                <Experience className="experience" test={this.props.main}  experienceClassVo={this.state.experienceClassVo} isBuyExperienceClass={this.state.isBuyExperienceClass}></Experience>
                <BuyRegularclass className="buyclass" level={this.state.card.level} ></BuyRegularclass>
                
              </div>)
       } else{
          if(!data.isRegulClass){
          return (<div>
                    {/*引入常规课购买模块 */}
                      <BuyRegularclass className="buyclass" level={this.state.card.level} ></BuyRegularclass>
                  </div>)
          }
          else{
            return (<div>
                   </div>)
          }
        }
      }
    }
  }

//  加载任务卡数据
  componentWillMount(){
    this.chooseClassState()
  }
  render () {
    return (
      <div className='task-component'>
        {/*判断 加载设备检测模块,体验课推荐模块，常规课推荐模块*/}
        {this.solveCardInformation(this.state.card)}
        {/* 判断是否加载组课中模块 */}
        {this.state.isArranging?<IsArranging className="buyclass"  ></IsArranging>:''}
        {/*判断 加载3种课程，6种状态，18个模块，再加一个复习模块*/}
        {this.state.classpush.map((item,index)=>{
          return this.loadercard(item)
        })}
       
      </div>
    )
  }
}
export default Task

